<?php
/**
 * 24tao首页展示
 * author liwei
 * date 2013-06-23
 */
class IndexAction extends CommonAction {

    //public function __construct(){

    //}

    public function index() {
        Load('extend');
        //查询明星信息
        $Star = M('star');
        //默认读取大陆明星
        $StarInfo = $Star->where('area=1')->select();
        if (!empty($StarInfo))
            foreach ($StarInfo as $key => $row) {
                //头像
                if ($row['photo']) {
                    $StarInfo[$key]['photo'] = '/Public/Uploads/Star/132_' . $row['photo'];
                }
            }
        //广告加载
        $Ad = M('recom_base_info');
        //recom_site为推荐广告类型
        $AdInfo = $Ad->where('recom_site=4')->order('recom_code')->select();
        //recom_site为推荐首页焦点
        $PicInfo = $Ad->where('recom_site=1')->order('recom_code')->select();

        //实例商品信息
        $Goods = M('goods_base_info');
        //推荐商品
        $RecomGoods = $Goods->order('goods_like_num desc')->limit('0,5')->select();

        //查询新品尝鲜分类
        $NewGoods = $Goods->where('goods_status=3')->order('pub_create_date desc')->select();

        //明星同款读取
        $StarSame = M('star_same');
        $starSameInfo = $StarSame->select();
        foreach ($starSameInfo as $key => $val) {
            $count = $Goods->where('goods_star_code=' . $val['star_id'])->count();
            $starInfo = $Star->where('id=' . $val['star_id'])->find();
            $starSameInfo[$key]['count'] = $count;
            $starSameInfo[$key]['fans_num'] = $starInfo['fans_num'];
            $starSameInfo[$key]['like_num'] = $starInfo['like_num'];
        }

		//查询人气聚集
		$Recom = M('recom_good');
        $userRecom = $Recom->limit('0,7')->order('createtime desc')->select();
		foreach($userRecom as $key=>$val){
			$userRecom[$key]['recom_user'] = $this->getUserField($val['uid']);
		}
        $this->assign('recomgoods', $RecomGoods);
        $this->assign('adinfo', $AdInfo);
        $this->assign('picinfo', $PicInfo);
        $this->assign('newgoods', $NewGoods);
        $this->assign('starinfo', $StarInfo);
        $this->assign('starSameInfo', $starSameInfo);
		$this->assign('userrecom', $userRecom);
        $this->assign('title', C('TITLE'));
        $this->display();
    }

    //明星列表切换返回
    public function showStar() {
        $area = $_GET['area'];
        //查询明星信息
        $Star = M('star');
        $StarInfo = $Star->where("area=$area")->select();
        if (!empty($StarInfo)) {
            $html = '';
            foreach ($StarInfo as $key => $row) {
                //头像
                if ($row['photo']) {
                    $StarInfo[$key]['photo'] = '/Public/Uploads/Star/132_' . $row['photo'];
                }
                $html .= "<li><a href='" . __APP__ . "/Star/starHome/starid/" . $row['id'] . "'><img src='" . $StarInfo[$key]['photo'] . "'></a></li>";
            }
        }

        $this->ajaxReturn($html);
    }
}